package edu.sctu.alex.projectPratice.test20150628;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;


import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectOutputStream;


/**
 * Created by alex on 2015/6/28.
 */
public class JsonPrase {

    public KeyOfJson parseJson(String jsonInfo){

        KeyOfJson keyOfJson = new KeyOfJson();

        JSONObject jsonObject = JSON.parseObject(jsonInfo);


        keyOfJson.error = jsonObject.getIntValue("error");

        keyOfJson.message = jsonObject.getString("message");

        keyOfJson.count = jsonObject.getString("count");

        keyOfJson.page  =jsonObject.getString("page");
        keyOfJson.size  =jsonObject.getString("size");

        JSONArray list = jsonObject.getJSONArray("list");


        for (int i = 0; i <list.size() ; i++) {

            JSONObject json =  list.getJSONObject(i);

            GoodsInfo goodsInfos = new GoodsInfo();
            goodsInfos.rec_id = json.getString("rec_id");
            goodsInfos.goods_id =  json.getString("goods_id");
            goodsInfos.category_id =  json.getString("category_id");
            goodsInfos.brand_id =  json.getString("brand_id");
            goodsInfos.goods_name =  json.getString("goods_name");
            goodsInfos.goods_image =  json.getString("goods_image");
            goodsInfos.goods_price =  json.getString("goods_price");
            goodsInfos.goods_type =  json.getString("goods_type");
            goodsInfos.goods_introduce =  json.getString("goods_introduce");
            goodsInfos.goods_device =  json.getString("goods_device");
            goodsInfos.goods_fictionsale =  json.getString("goods_fictionsale");
            goodsInfos.rec_time =  json.getString("rec_time");
            goodsInfos.rec_top =  json.getString("rec_top");
            goodsInfos.recommend_num =  json.getString("recommend_num");
            goodsInfos.goods_likes =  json.getString("goods_likes");
            goodsInfos.s_goods_device =  json.getString("s_goods_device");
            goodsInfos.s_rec_time =  json.getString("s_rec_time");

            keyOfJson.list.add(goodsInfos);

        }



        return keyOfJson;
    }




}

